{smcl}
{txt}{sf}{ul off}{.-}
      name:  {res}<unnamed>
       {txt}log:  {res}C:\Users\js0072\OneDrive - University of Surrey\Desktop\Full replica\results\BBComtrade_hetcoeff_16Jun2022.smcl
  {txt}log type:  {res}smcl
 {txt}opened on:  {res}16 Jun 2022, 13:45:12
{txt}r; t=0.00 13:45:12

{com}. 
. *global fetype="exp_year imp_year"
. global fetype="exp_year_product imp_year_product imp_exp_product"
{txt}r; t=0.00 13:45:12

{com}. 
.         foreach method in ols ppml {c -(}
{txt}  2{com}.         foreach level in 2 4 {c -(}
{txt}  3{com}. 
.                 foreach regs in "fta l1fta l2fta" {c -(}
{txt}  4{com}.                 
.                 disp("`method'")
{txt}  5{com}.                 disp("`level'")
{txt}  6{com}.                 disp("$fetype")
{txt}  7{com}.                                 
.                         * create dataset at appropriate aggregation level
.                         use "$dtapath\BB_allyears_all_zeros_2000obsplus.dta", replace
{txt}  8{com}.                         cap gen sitc_`level'_digit=substr(commoditycode,4,`level')
{txt}  9{com}.                         qui drop if year>2000
{txt} 10{com}.                         if `level'<4 {c -(}
{txt} 11{com}.                                 collapse (sum) imports (mean) comlang_off comcol curcol col45 distw EIA WTO_j WTO_i WTO PTA scott_fta fta, by(importeriso3 exporteriso3 sitc_`level'_digit year)
{txt} 12{com}.                         {c )-}
{txt} 13{com}.                         
.                         * generate lags and log imports
.                         if "`method'"=="ols" {c -(}
{txt} 14{com}.                                         *keep if imports~=0   // o/w we get more lags than in original B&B (2007) paper!
.                         {c )-}
{txt} 15{com}.                         bys importeriso3 exporteriso3 sitc_`level'_digit (year):  gen l1fta=fta[_n-1] if year==year[_n-1]+5 | (year==1965 & year==year[_n-1]+3)
{txt} 16{com}.                         bys importeriso3 exporteriso3 sitc_`level'_digit (year):  gen l2fta=fta[_n-2] if year==year[_n-2]+10 | (year==1970 & year==year[_n-2]+8)
{txt} 17{com}.                         bys importeriso3 exporteriso3 sitc_`level'_digit (year):  gen f1fta=fta[_n+1] if year==year[_n+1]-5 | (year==1962 & year==year[_n+1]-3)
{txt} 18{com}. 
.                         qui gen limports=log(imports)
{txt} 19{com}.                         qui egen exp_year_product=group(exporteriso3 sitc_`level'_digit year )
{txt} 20{com}.                         qui egen imp_year_product=group(importeriso3 sitc_`level'_digit year)
{txt} 21{com}.                         qui egen imp_exp_product=group(importeriso3 exporteriso3 sitc_`level'_digit)
{txt} 22{com}.                         codebook exp_year imp_year 
{txt} 23{com}.                         qui egen pairid_str=concat(exporteriso3 importeriso3)
{txt} 24{com}.                         qui encode pairid_str, gen(pairid)
{txt} 25{com}.                         
.                         foreach var in fta l1fta l2fta {c -(}
{txt} 26{com}.                                 qui gen coeff_`var'=.
{txt} 27{com}.                                 qui gen se_`var'=.
{txt} 28{com}.                         {c )-}
{txt} 29{com}. 
.                         * now poisson with ppmlhdfe for each SITC code separately
.                         qui egen sitccount=group(sitc_`level'_digit)
{txt} 30{com}.                         cap drop temp
{txt} 31{com}.                         qui egen temp=max(sitccount)
{txt} 32{com}.                         local countsitc=temp
{txt} 33{com}.                         disp `countsitc'
{txt} 34{com}.                         qui drop temp
{txt} 35{com}.                         save tempfile.dta, replace
{txt} 36{com}.                                         
.                         forvalues sitccode=1(1)`countsitc' {c -(}
{txt} 37{com}.                                 disp `sitccode'
{txt} 38{com}.                                 use tempfile.dta, replace
{txt} 39{com}.                                 qui keep if sitccount==`sitccode'
{txt} 40{com}.                                 qui count if imports~=0
{txt} 41{com}.                                 qui gen noposobs=r(N)
{txt} 42{com}.                                 qui gen noobs=_N
{txt} 43{com}.                                         if "`method'"=="ppml" {c -(}
{txt} 44{com}.                                                 noisily: capture ppmlhdfe imports `regs' if imports~=., abs($fetype) cluster(pairid) separation(fe mu)
{txt} 45{com}.                                         {c )-} 
{txt} 46{com}.                                         if "`method'"=="ols" {c -(}
{txt} 47{com}.                                                 noisily: capture reghdfe limports `regs' if imports~=., abs($fetype) cluster(pairid)
{txt} 48{com}.                                         {c )-} 
{txt} 49{com}.                                         qui gen temp=e(converged)
{txt} 50{com}.                                         qui replace temp=1 if temp==.
{txt} 51{com}.                                         global conv=temp
{txt} 52{com}.                                         drop temp
{txt} 53{com}.                                         *disp $conv
.                                         if $conv==0 {c -(}
{txt} 54{com}.                                         exit // (no convergence)
{txt} 55{com}.                                         {c )-}
{txt} 56{com}.                                         if $conv==1 {c -(}
{txt} 57{com}.                                                 foreach var in `regs' {c -(}
{txt} 58{com}.                                                         capture replace coeff_`var'=_b[`var'] if sitccount==`sitccode'
{txt} 59{com}.                                                         capture replace se_`var'=_se[`var'] if sitccount==`sitccode'
{txt} 60{com}.                                                 {c )-}
{txt} 61{com}.                                         {c )-}
{txt} 62{com}.                                         qui bys sitc_`level'_digit: keep if _n==1
{txt} 63{com}.                                         keep sitc_`level'_digit coeff_* se_* noobs noposobs
{txt} 64{com}.                                         qui gen sitcagglevel="`level'-digit"
{txt} 65{com}.                                         qui gen converged=$conv
{txt} 66{com}.                                         order sitcagglevel sitc_`level'_digit
{txt} 67{com}.                                         qui save temp`sitccode'.dta, replace
{txt} 68{com}.                                 {c )-}
{txt} 69{com}.                         {c )-}
{txt} 70{com}.                         
.                         use temp1.dta, replace
{txt} 71{com}.                         erase temp1.dta
{txt} 72{com}.                         forvalues x=2(1)`countsitc' {c -(}
{txt} 73{com}.                                 append using temp`x'.dta
{txt} 74{com}.                                 erase temp`x'.dta
{txt} 75{com}.                         {c )-}
{txt} 76{com}.                         local fetype=subinstr("$fetype"," ","",.)
{txt} 77{com}.                         save coeffhet_`method'_`fetype'_`level'_digit.dta, replace
{txt} 78{com}.                 {c )-}
{txt} 79{com}.         {c )-}
ols
2
exp_year_product imp_year_product imp_exp_product
{txt}(547,200 missing values generated)
(1,094,400 missing values generated)
(547,200 missing values generated)

{txt}{hline}
{res}exp_year_product{right:group(exporteriso3 sitc_2_digit year)}
{txt}{hline}

{col 19}type:  numeric ({res}float{txt})

{col 18}range:  [{res}1{txt},{res}51840{txt}]{col 55}units:  {res}1
{col 10}{txt}unique values:  {res}51,840{col 51}{txt}missing .:  {res}0{txt}/{res}4,924,800

{txt}{col 19}mean:{res}{col 26} 25920.5
{txt}{col 15}std. dev:{res}{col 26} 14964.9

{txt}{col 12}percentiles:{col 32}10%{col 42}25%{col 52}50%{col 62}75%{col 72}90%
{res}{col 27}  5184.5{col 37} 12960.5{col 47} 25920.5{col 57} 38880.5{col 67} 46656.5

{txt}{hline}
{res}imp_year_product{right:group(importeriso3 sitc_2_digit year)}
{txt}{hline}

{col 19}type:  numeric ({res}float{txt})

{col 18}range:  [{res}1{txt},{res}51840{txt}]{col 55}units:  {res}1
{col 10}{txt}unique values:  {res}51,840{col 51}{txt}missing .:  {res}0{txt}/{res}4,924,800

{txt}{col 19}mean:{res}{col 26} 25920.5
{txt}{col 15}std. dev:{res}{col 26} 14964.9

{txt}{col 12}percentiles:{col 32}10%{col 42}25%{col 52}50%{col 62}75%{col 72}90%
{res}{col 27}  5184.5{col 37} 12960.5{col 47} 25920.5{col 57} 38880.5{col 67} 46656.5
60
{txt}(note: file tempfile.dta not found)
file tempfile.dta saved
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
(note: file coeffhet_ols_exp_year_productimp_year_productimp_exp_product_2_digit.dta not found)
file coeffhet_ols_exp_year_productimp_year_productimp_exp_product_2_digit.dta saved
ols
4
exp_year_product imp_year_product imp_exp_product
(5,253,120 missing values generated)
(10,506,240 missing values generated)
(5,253,120 missing values generated)

{txt}{hline}
{res}exp_year_product{right:group(exporteriso3 sitc_4_digit year)}
{txt}{hline}

{col 19}type:  numeric ({res}float{txt})

{col 18}range:  [{res}1{txt},{res}497664{txt}]{col 55}units:  {res}1
{col 10}{txt}unique values:  {res}497,664{col 51}{txt}missing .:  {res}0{txt}/{res}47,278,080

{txt}{col 19}mean:{res}{col 26}  248833
{txt}{col 15}std. dev:{res}{col 26}  143663

{txt}{col 12}percentiles:{col 32}10%{col 42}25%{col 52}50%{col 62}75%{col 72}90%
{res}{col 27}   49767{col 37}  124417{col 47}  248833{col 57}  373249{col 67}  447898

{txt}{hline}
{res}imp_year_product{right:group(importeriso3 sitc_4_digit year)}
{txt}{hline}

{col 19}type:  numeric ({res}float{txt})

{col 18}range:  [{res}1{txt},{res}497664{txt}]{col 55}units:  {res}1
{col 10}{txt}unique values:  {res}497,664{col 51}{txt}missing .:  {res}0{txt}/{res}47,278,080

{txt}{col 19}mean:{res}{col 26}  248833
{txt}{col 15}std. dev:{res}{col 26}  143663

{txt}{col 12}percentiles:{col 32}10%{col 42}25%{col 52}50%{col 62}75%{col 72}90%
{res}{col 27}   49767{col 37}  124417{col 47}  248833{col 57}  373249{col 67}  447898
576
{txt}file tempfile.dta saved
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
(note: file coeffhet_ols_exp_year_productimp_year_productimp_exp_product_4_digit.dta not found)
file coeffhet_ols_exp_year_productimp_year_productimp_exp_product_4_digit.dta saved
ppml
2
exp_year_product imp_year_product imp_exp_product
(547,200 missing values generated)
(1,094,400 missing values generated)
(547,200 missing values generated)

{txt}{hline}
{res}exp_year_product{right:group(exporteriso3 sitc_2_digit year)}
{txt}{hline}

{col 19}type:  numeric ({res}float{txt})

{col 18}range:  [{res}1{txt},{res}51840{txt}]{col 55}units:  {res}1
{col 10}{txt}unique values:  {res}51,840{col 51}{txt}missing .:  {res}0{txt}/{res}4,924,800

{txt}{col 19}mean:{res}{col 26} 25920.5
{txt}{col 15}std. dev:{res}{col 26} 14964.9

{txt}{col 12}percentiles:{col 32}10%{col 42}25%{col 52}50%{col 62}75%{col 72}90%
{res}{col 27}  5184.5{col 37} 12960.5{col 47} 25920.5{col 57} 38880.5{col 67} 46656.5

{txt}{hline}
{res}imp_year_product{right:group(importeriso3 sitc_2_digit year)}
{txt}{hline}

{col 19}type:  numeric ({res}float{txt})

{col 18}range:  [{res}1{txt},{res}51840{txt}]{col 55}units:  {res}1
{col 10}{txt}unique values:  {res}51,840{col 51}{txt}missing .:  {res}0{txt}/{res}4,924,800

{txt}{col 19}mean:{res}{col 26} 25920.5
{txt}{col 15}std. dev:{res}{col 26} 14964.9

{txt}{col 12}percentiles:{col 32}10%{col 42}25%{col 52}50%{col 62}75%{col 72}90%
{res}{col 27}  5184.5{col 37} 12960.5{col 47} 25920.5{col 57} 38880.5{col 67} 46656.5
60
{txt}file tempfile.dta saved
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
(note: file coeffhet_ppml_exp_year_productimp_year_productimp_exp_product_2_digit.dta not found)
file coeffhet_ppml_exp_year_productimp_year_productimp_exp_product_2_digit.dta saved
ppml
4
exp_year_product imp_year_product imp_exp_product
(5,253,120 missing values generated)
(10,506,240 missing values generated)
(5,253,120 missing values generated)

{txt}{hline}
{res}exp_year_product{right:group(exporteriso3 sitc_4_digit year)}
{txt}{hline}

{col 19}type:  numeric ({res}float{txt})

{col 18}range:  [{res}1{txt},{res}497664{txt}]{col 55}units:  {res}1
{col 10}{txt}unique values:  {res}497,664{col 51}{txt}missing .:  {res}0{txt}/{res}47,278,080

{txt}{col 19}mean:{res}{col 26}  248833
{txt}{col 15}std. dev:{res}{col 26}  143663

{txt}{col 12}percentiles:{col 32}10%{col 42}25%{col 52}50%{col 62}75%{col 72}90%
{res}{col 27}   49767{col 37}  124417{col 47}  248833{col 57}  373249{col 67}  447898

{txt}{hline}
{res}imp_year_product{right:group(importeriso3 sitc_4_digit year)}
{txt}{hline}

{col 19}type:  numeric ({res}float{txt})

{col 18}range:  [{res}1{txt},{res}497664{txt}]{col 55}units:  {res}1
{col 10}{txt}unique values:  {res}497,664{col 51}{txt}missing .:  {res}0{txt}/{res}47,278,080

{txt}{col 19}mean:{res}{col 26}  248833
{txt}{col 15}std. dev:{res}{col 26}  143663

{txt}{col 12}percentiles:{col 32}10%{col 42}25%{col 52}50%{col 62}75%{col 72}90%
{res}{col 27}   49767{col 37}  124417{col 47}  248833{col 57}  373249{col 67}  447898
576
{txt}file tempfile.dta saved
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
(note: file coeffhet_ppml_exp_year_productimp_year_productimp_exp_product_4_digit.dta not found)
file coeffhet_ppml_exp_year_productimp_year_productimp_exp_product_4_digit.dta saved
r; t=7411.77 15:48:43

{com}. 
. erase tempfile.dta
{txt}r; t=0.48 15:48:44

{com}. log close
      {txt}name:  {res}<unnamed>
       {txt}log:  {res}C:\Users\js0072\OneDrive - University of Surrey\Desktop\Full replica\results\BBComtrade_hetcoeff_16Jun2022.smcl
  {txt}log type:  {res}smcl
 {txt}closed on:  {res}16 Jun 2022, 15:48:44
{txt}{.-}
{smcl}
{txt}{sf}{ul off}